package xkp.lesson1;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Server {
    public static void main(String[] args) throws IOException {
        System.out.println("服务器启动....");
        //NIO
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.bind(new InetSocketAddress(8888));
        //设置为非阻塞模式
        serverSocketChannel.configureBlocking(false);
        //当配置为非阻塞的话，面临的问题为 此处通道不管有没有客户端连接，都不会阻塞，如何和得知有客户端连接?????
        SocketChannel socketChannel = serverSocketChannel.accept();
        new Thread(){
            @Override
            public void run() {
                while(true){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        System.out.println("----------------------------------");
    }
}
